#include <iostream>
#include <vector>
using namespace std;
string longestCommonPrefix(vector<string> &strs)
{
    string str;
    int n = strs.size();
    while (true)
    {
        char p = '0';
        for (int i = 0; i < n; i++)
        {
            //cout<<i<<" ";
            if (strs[i].length() == 0)
                return str;
            p = p == '0' ? strs[i][0] : p;
            if (strs[i][0] != p)
                return str;
            
            strs[i].erase(0, 1);
            //cout<<strs[i]<<" ";
        }
       // cout<<endl;
       str.append(1,p);
        p = '0';
    }
}
int main()
{
    string str[3]={"flower","flow","flight"};
    vector<string> aa(str,str+3);
    cout<<longestCommonPrefix(aa);
    return 0;
}